<%--
  Created by IntelliJ IDEA.
  User: zhazha
  Date: 2021/9/1
  Time: 11:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <%
        Object user = session.getAttribute("user");
        if(user != null){
            response.sendRedirect("index.jsp");
            return;
        }
    %>
    <script type="text/javascript">
        if(window != top){
            top.location.href=location.href;
        }
    </script>
    <title>登陆</title>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="css/main.css">
</head>
<body>
<div class="login_head">
    <div class="container">
        <img src="images/logo.png">
    </div>
</div>
<form method="post" action="/doUser?method=checkLogin" onsubmit="return checkLogin()">
    <div class="login_banner">
        <div class="container">
            <div class="login">
                <div class="login_in">
                    <div class="login_h">后台登陆</div>
                    <div class="user_login">
                        <input type="text" name="username" id="loginUserName" placeholder="账号" value="${sessionScope.loginUserName}" onblur="checkLoginName()">
                        <span style="color: red" id="loginUserNameErr"></span>
                        <input type="password" name="pwd" id="loginPwd" placeholder="密码" onblur="checkLoginPWD()">
                        <span style="color: red" id="loginPWDErr">${sessionScope.loginErrMsg}</span>
                    </div>
                    <div class="img_code">
                        <input type="text" name="Captcha" id="Captcha" placeholder="验证码" onblur="checkCaptcha()"><img src="getcaptcha.sl" alt="验证码" name="checkImg" id="checkImg" style="position:relative; top:5px; left:20px; "  onClick="document.getElementById('checkImg').src='getcaptcha.sl?temp='+ (new Date().getTime().toString(36)); return false"/><br>
                        <span style="color: red" id="captchaErr">${sessionScope.loginCaptchaErrMsg}</span>
                    </div>
                    <button type="submit" class="login_btn">登录</button>
                </div>

            </div>
        </div>
    </div>
</form>
<div class="login_end text_center">版权所有&copy;：电子股份有限公司  豫ICP备08102576号  未经授权本站内容禁止私自转载使用！</div>
<%
    session.removeAttribute("loginErrMsg");
    session.removeAttribute("loginUserName");
    session.removeAttribute("loginCaptchaErrMsg");
%>
</body>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<script type="text/javascript">
    function checkCaptcha(){
        var check = /^\d{4}$/;
        var cap = $('#Captcha').val();
        if (check.test(cap)){
            $('#captchaErr').html("");
            return true;
        }else{
            $('#captchaErr').html("验证码为4位数字");
            return false;
        }
    }
    function checkLoginName(){
        var check = /^.{1,9}$/;
        var loginName = $('#loginUserName').val();
        if(check.test(loginName)){
            $('#loginUserNameErr').text("");
            return true;
        }else{
            $('#loginUserNameErr').text("账号不能为空");
            return false;
        }
    }
    function checkLoginPWD(){
        var check = /^.{1,9}$/;
        var loginPWD = $('#loginPwd').val();
        if(check.test(loginPWD)){
            $('#loginPWDErr').text("");
            return true;
        }else {
            $('#loginPWDErr').text("密码不能为空");
            return false;
        }
    }
    function checkLogin(){
        return checkCaptcha() && checkLoginName() && checkLoginPWD() ;
    }
</script>
</html>
